package oss

import (
	"context"
	"group-buy/oss"

	"group-buy/group_buy/internal/svc"
	"group-buy/group_buy/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type TokenLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TokenLogic {
	return &TokenLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TokenLogic) Token(req *types.GetTokenReq) (resp *types.OssToken, err error) {
	token := oss.GetPolicyToken(req.Dir)
	return &types.OssToken{
		AccessKeyId: token.AccessKeyId,
		Host:        token.Host,
		Expire:      token.Expire,
		Signature:   token.Signature,
		Policy:      token.Policy,
		Directory:   token.Directory,
		Callback:    token.Callback,
	}, nil
}
